/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 10, 2011 12:16:28 PM
 */
package carrello.model.association;

import carrello.model.entities.*;
import carrello.util.EntityManagerUtil;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.*;

@NamedQueries({
	@NamedQuery(
	    name = "getAllInvoices",
	    query = "from Invoice"
	    ),
        @NamedQuery(
            name = "getAllInvoicesByUserId",
            query = "from Invoice where user_id = :id"
        )
        })
@Entity
@Table(name = "Invoice")
public class Invoice {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "invoice_id")
    private int invoiceId;
    private int quantity;
    private String cost;
    private String productname;
    private char status;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date purchase_date;
    
//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "product_id", nullable = true)
//    private Product product;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = true)
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "processor_id", nullable = true)
    private PaymentProcessor processor;

    public Invoice() {
    }

    public Invoice(int invoiceId, int quantity, String cost, String productname, Date purchase_date, char status, User user, PaymentProcessor processor) {
        this.invoiceId = invoiceId;
        this.quantity = quantity;
        this.cost = cost;
        this.purchase_date = purchase_date;
        this.status = status;
        this.productname = productname;
        this.user = user;
        this.processor = processor;
    }
  
    public String getCost() {
        return cost;
    }

    public void setCost(String cost) {
        this.cost = cost;
    }

    public int getInvoiceId() {
        return invoiceId;
    }

    public void setInvoiceId(int invoiceId) {
        this.invoiceId = invoiceId;
    }

    public PaymentProcessor getProcessor() {
        return processor;
    }

    public void setProcessor(PaymentProcessor processor) {
        this.processor = processor;
    }
    
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Date getPurchase_date() {
        return purchase_date;
    }

    public void setPurchase_date(Date purchase_date) {
        this.purchase_date = purchase_date;
    }

    public char getStatus() {
        return status;
    }

    public void setStatus(char status) {
        this.status = status;
    }

    
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public static List<Invoice> getAllInvoices () {
        List<Invoice> inv = EntityManagerUtil.getEntityManager().getQuery("getAllInvoices").list();
        return inv;
    }


    public String getProductname() {
        return productname;
    }

    public static List<Invoice> getAllInvoicesByUserId ( int userid ) {
        List<Invoice> inv = EntityManagerUtil.getEntityManager().getQuery("getAllInvoicesByUserId").setParameter("id", userid).list();
        return inv;
    }
    public void setProductname(String productname) {
        this.productname = productname;
    }
    
}
